package com.nuc.bigdata.controller;

import com.nuc.bigdata.orm.feign.PhotoShareMenuFeign;
import com.nuc.bigdata.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;

/**
 * @author tianhao.luo
 * @date 2019/12/12 15:04
 */
@Api(value = "菜单项controller")
@RestController
@RequestMapping("/oa-photos")
public class MenuController {
    private final MenuService menuService;

    @Autowired
    MenuController(MenuService menuService) {
        this.menuService = menuService;

    }

    /**
     * 获取所有图片菜单
     *
     * @return 菜单ArrayList
     */
    @ApiOperation(value = "获取所有菜单", notes = "提供给front服务的feign", tags = {"获取菜单接口"})
    @GetMapping("/menus")
    public ArrayList<PhotoShareMenuFeign> listAllMenu() {
        return menuService.listAllFeign();
    }


    /**
     * 创建图片资讯菜单项
     *
     * @param menuItemTitle 菜单项标题
     * @param userId        用户唯一标识
     */
    @ApiOperation(value = "创建新菜单项", tags = {"增删改菜单接口"})
    @PostMapping("/menu")
    public void createMenuItem(
            @ApiParam(value = "菜单项标题", required = true) @RequestParam("menuItemTitle") @NotEmpty String menuItemTitle,
            @ApiParam(required = true) @RequestParam("userId") @NotEmpty String userId) {
        menuService.createMenuItem(menuItemTitle, userId);
    }

    /**
     * 移除一个菜单项
     * @param menuItemId 菜单项唯一标识
     */
    @ApiOperation(value = "删除菜单项", tags = {"增删改菜单接口"})
    @DeleteMapping("/menus/{menuItemId}")
    public void removeMenuItem(
            @ApiParam(value = "菜单项唯一标识",required = true) @PathVariable("menuItemId") @NotEmpty String menuItemId) {
        menuService.removeMenuItem(menuItemId);
    }

    /**
     * 修改菜单项
     * @param menuItemId 菜单项唯一标识
     * @param menuItemTitle 菜单项字符串
     * @param userId 用户唯一标识
     */
    @ApiOperation(value = "修改菜单项", tags = {"增删改菜单接口"})
    @PutMapping("/menus/{menuItemId}")
    public void updateMenuItem(
            @ApiParam(value = "菜单唯一标识",required = true) @PathVariable("menuItemId") @NotEmpty String menuItemId,
            @ApiParam(value = "菜单新标题",required = true) @RequestParam("menuItemTitle") @NotEmpty String menuItemTitle,
            @ApiParam(required = true) @RequestParam("userId") @NotEmpty String userId) {
        menuService.updateMenuItem(menuItemId, menuItemTitle, userId);
    }

}
